{template 'common/header'}
{template 'common'}
<script type="text/javascript" src="resource/js/lib/jquery-ui-1.10.3.min.js"></script>
<link type="text/css" rel="stylesheet" href="../addons/kbwdl_shequzufang/images/uploadify_t.css" />
<script type="text/javascript" src="../addons/kbwdl_shequzufang/style/script/jquery.bigautocomplete.js"></script>
<link type="text/css" rel="stylesheet" href="../addons/kbwdl_shequzufang/style/css/my.css" />
 
 
<div class="kb-container">
    <div class="kb-slide">
        <div style="width: 100%; height: 1px;"></div>
        <div class="kb-slide1">
            <div class="list-group">
                {loop $submenus $menukey $menu}
                <a href="<?php echo $this->createWebUrl('send',['op'=>$menukey] );?>"
                    class="list-group-item <?php if($operation==$menukey ) echo 'active';?> ">
                    {$menu['name']}
                </a>
                {/loop}
                <a href="<?php echo $this->createWebUrl('sendlist',['op'=> $operation] );?>"
                    class="list-group-item">
                    返回列表
                </a>
            </div>
        </div>
    </div>
    <div class="kb-main">
        <!-- kb-main start -->
        <div class="main">
            <form name="sendform" action="" onsubmit="return formcheck();" method="post" class="form-horizontal form"
                enctype="multipart/form-data" id="form1">
                <input type="hidden" name="data[rent_type]" value="{$renttype}" title="0=出售2=出租3=转让">
                <input type="hidden" name="data[zhutype]" value="{$zhutype}" title="0=二手房2=租房3=新房4=商铺 7=厂房8=仓库9=写字楼">
                <div class="panel panel-default">

                    <div class="panel-body">
                        <ul class="nav nav-tabs" id="myTab">
                             
                            <li class="active"><a href="#tab_basic">
                          {if empty($item['id'])}添加{else} 编辑{/if}<span style="color: red;">{$submenus[$operation]['name']}</span>基本信息</a>
                            </li>
                          {if $zhutype==3} 
                          <li><a href="#tab_loupan">楼盘资料</a></li> 
                          {/if}
                            <li><a href="#tab_param">自定义属性</a></li>

                        </ul>
                        <div class="tab-content">
                            <div class="tab-pane  active" id="tab_basic">
                                <!--按发布的变量，加载模板类型-->
                                {template $template_name} 

 
                                {template 'send/house_des'} 
                               
                            </div>
                            {if $zhutype==3} 
                            <div class="tab-pane" id="tab_loupan">
                                {template 'send/loupan'}
                            </div>
                            {/if}
                            <div class="tab-pane" id="tab_param">
                                {template 'send/house_param'}
                            </div>
                        </div>

                    </div>

                </div>

                <div class="form-group col-sm-11">
                    <input type="submit" name="submit" onclick="form.backway.value=1" value="提交保存" class="btn btn-primary col-lg-2" />
                    <input type="submit" name="submit"  onclick="form.backway.value=2" value="保存再新增" class="btn btn-default col-lg-2" />
                    <input type="submit" name="submit" onclick="form.backway.value=3"  value="保存并返回列表" class="btn btn-warning col-lg-2" />
                    <input type="hidden" name="token" value="{$_W['token']}" />
                    <input type="hidden" name="referer" value="{$referer}" />
                    <input type="hidden" name="backway" value="1" />
                </div>
            </form>
        </div>
        <!-- kb-main end -->
    </div>
</div>

<!-- 新建商圈的弹窗 -->
 <!--新建弹窗-->
<style>
    #owner-modal .modal-dialog{
      min-width: 500px;
      width: 600px;
    }  
  </style>
  <div class="modal modal-type"  tabindex="-1" role="dialog" id="owner-modal">
      <div class="modal-dialog" role="document">
          <div class="modal-content">
              <div class="modal-header clearfix">
                  新建
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              </div>
              <div class="modal-body">
                  <div class="row">
                       <form name="modal_quan_form" class="form-horizontal form">
                        
                        <div class="form-group">                            
                            <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                                <span style='color:red'>*</span>商圈名称：</label>
                                <div class="col-sm-8 col-xs-12">
                                    <input type="text" name="quan_name" id="quan_name" class="form-control"
                                         autocomplete="off"  placeholder="请输入名称" value="" />                                        
                                </div>
                        </div>

                        <div class="form-group">
                            <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                                <span style='color:red'></span>所在区域：</label>
                            <div class="col-sm-8 col-xs-8">
                                      <div class="input-group form-group">
                             {if $citys}    
                            <span style="display:table-cell; ">                          
                         {php echo form_element::select($citys,'data[city_id]','city_id',$item['city_id'],'1','city', 'onchange="onCitychange(this,\"#modal-areas\")"');}
                               </span>
                               {/if}  
                             <span id="modal-areas" style="display:table-cell; ">         
                         {php echo  form_element::select($sec['areas'],'quan_area','quan_area');}
                             </span>
                                   
                                 </div>   
                            </div>
                        </div> 

                       
                        <div class="form-group" style="height: 90px;">
                            <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                        <div id="alert-container" class="col-sm-8 col-xs-12" style="display: none;">
                            <div class="alert alert-warning alert-dismissible" role="alert"> 
                               <div id="alert_message"></div>
                            </div>
                          </div>
                        </div>


                       </form> 
                        
                  </div>
              </div>
              <div class="modal-footer">
                  <button type="button" onclick="saveAreaQuan()" class="btn btn-primary retreat-submit">提交</button>
                  <button type="button" class="btn btn-default"  data-dismiss="modal">取消</button>
              </div>
          </div>
      </div>
  </div>
  <!-- 新建商圈的弹窗 -->


<script type="text/javascript">
    //商圈增加
    function saveAreaQuan()
    {
        var area  = $("select#area").val();        
        var form = document.getElementsByName("modal_quan_form")[0];
        if( !form.quan_area.value ){
            $("select[name='quan_area']").val(area );
        }
        if(!form.quan_area.value || !form.quan_name.value ){
            $("#alert_message").html("请选择区域和输入名称！")
             $("#alert-container").fadeIn();
             setTimeout(function(){ $("#alert-container").fadeOut() },2000)
             return false;
        }
        $.ajax({
                type:'POST',
                url: "{php echo $this->createWebUrl('send', array('op'=>'savequan'))}"  ,
                data:{ area: form.quan_area.value, name: form.quan_name.value},
                success: function (ret) {
                    window.areas = JSON.parse(ret)
                    $("select[name='data[quan]']").append('<option value="'+form.quan_name.value+'">'+form.quan_name.value+'</option>')
                    $("select[name='data[quan]']").val(form.quan_name.value)
                    $("select[name='data[area]']").val(form.quan_area.value)
                    form.reset()
                    $('#owner-modal').modal('hide');                   
                }
            });
    }
    /*小区自动补充*/
    $('#village_name').bigAutocomplete(
        {
            url: "{php echo $this->createWebUrl('sajax', array('op' => 'autovillage'))}",
            callback: function (item) {
                $("input[name='data[village_id]']").val(item.id);
                $(currentInputText).val(item.inputname);
            }
        });


    var category = {php echo json_encode($children) };
    /*城市下拉更改时重新加载区域 target是加入*/
    function onCitychange(obj, target_id) {
            var id = obj.value;
            $.ajax({
                url: "{php echo $this->createWebUrl('send', array('op'=>'cityareas'))}" + "&id=" + id,
                success: function (ret) {
                    $(target_id).html(ret);                    
                }
            });

        }
        function formcheck() {
            if (!$("#area").val()) {
                Tip.focus("area", "请选择所在区域!", "right");
                return false;
            }
            if ($("#title").isEmpty()) {
                $('#myTab a[href="#tab_basic"]').tab('show');
                Tip.focus("title", "请输入房源标题!", "right");
                return false;
            }
            return true;
        }
        function maketitle()
        {
            var form = document.getElementsByName('sendform')[0];
            var title = new Array();
             //title.push(form.area.value);
             title.push(form.quan.value);
             title.push(form.village_name.value);
             title.push(form.house_type.value);
             if(form.room.value)
                title.push(form.room.value + '房' + form.hall.value + '厅' + form.garder.value + '卫');
            
            title.push(form.superficie.value ? form.superficie.value + '㎡':'');

            // title.push(form.loyer.value ? (form.loyer.value +""+  form.prix_unitaire.value):'');
 
             form.title.value = title.join(" ");
        }
    //解析url
    function getQuery(url, field, value) {
        var theRequest = {};
        if (url.indexOf("?") != -1) {
            var str = url.split('?')[1];
            var strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                if (strs[i].split("=")[0] && unescape(strs[i].split("=")[1])) {
                    var name = strs[i].split("=")[0];
                    theRequest[name] = unescape(strs[i].split("=")[1]);
                    
                }
            }
        }
        theRequest[field] = value;
        var urlData = '';
		for (var key in theRequest ) {			 
            urlData += key + '=' + theRequest[key] + '&' ;           
		} 
        return urlData;
    }  
    function navtype(t){
        var querystring = getQuery(window.location.href, 'renttype', t);
        var host = window.location.href.split("?")[0];
        window.location.href = host + "?" + querystring;
        
    }
            //覆盖打开地图方法
    function showCoordinate(elm){
        require(["util"], function(util){
            var val = {};
            val.lng = parseFloat($(elm).parent().prev().prev().find(":text").val());
            val.lat = parseFloat($(elm).parent().prev().find(":text").val());
            util.map(val, function(r){
                $(elm).parent().prev().prev().find(":text").val(r.lng);
                $(elm).parent().prev().find(":text").val(r.lat);
            });
            
        });
        var address = $("#city_id option:selected").text() + $("#area").val()+ $("#quan").val() +$("#village_name").val();
		setTimeout(() => {
            $("#map-dialog input[type='text']").val(address) ;
            $("#map-dialog .modal-body .btn").trigger("click")
        }, 1500); 	 
        
			
    }
</script>
{template 'common/footer'}